home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
58189
/
58189.xpi
/
chrome
/
content
/
whitelist.js
< prev
next >
Wrap
Text File
|
2010-01-06
|
5KB
|
192 lines
/*
* This class handles the functionality of the whitelist window
*/
Components.utils.import("resource://csfiremodules/CsFireCommon.jsm");
CsFire.XulWhitelist = new function() {};
/*
* This function enables/disables the ADD button when appropriate
*/
CsFire.XulWhitelist.updateAddButtonStatus = function() {
var addbtn = document.getElementById('addbtn');
var originbox = document.getElementById('urlboxorigin');
var destinationbox = document.getElementById('urlboxdestination');
addbtn.disabled = !(originbox.value.length > 0 && destinationbox.value.length > 0);
}
/*
* This function enables/disables the DEL button when appropriate
*/
CsFire.XulWhitelist.updateDelButtonStatus = function() {
var list = document.getElementById('whitelist');
var rules = document.getElementById('listcontents');
var delbtn = document.getElementById('delbtn');
var disabled = true;
for (var i=rules.childNodes.length-1 ; i>=0 && disabled; i--) {
if (list.view.selection.isSelected(i)) {
disabled = false;
}
}
delbtn.disabled = disabled;
}
/*
* Updates the "enabled" status of entries in the whitelists.
*/
CsFire.XulWhitelist.updateEntries = function() {
var entries = CsFire.Whitelist.getList();
var list = document.getElementById('whitelist');
var rules = document.getElementById('listcontents');
for (var i=rules.childNodes.length-1 ; i>=0 ; i--) {
var node = rules.childNodes[i];
var origin = node.firstChild.childNodes[0].getAttribute('label');
var destination = node.firstChild.childNodes[1].getAttribute('label');
var value = node.firstChild.childNodes[2].getAttribute('value');
for(var j = 0; j < entries.length; j++) {
var entry = entries[j];
if(entry && entry.origin == origin && entry.destination == destination) {
if(value === "true") {
if(!entry.enabled) {
CsFire.Whitelist.updateEntryStatus(entry);
}
}
else {
if(entry.enabled) {
CsFire.Whitelist.updateEntryStatus(entry);
}
}
}
}
}
}
/*
* Initializes the components of the window
*/
CsFire.XulWhitelist.init = function() {
this.clearList();
this.loadList();
}
/*
* Removes all items from the domain list (only in the view, not the controller)
*/
CsFire.XulWhitelist.clearList = function() {
var rules = document.getElementById('listcontents');
while (rules.hasChildNodes()) rules.removeChild(rules.firstChild);
}
/*
* Loads items from controller in the view (populates domain list)
*/
CsFire.XulWhitelist.loadList = function() {
var list = CsFire.Whitelist.getList();
for(var i = 0; i < list.length; i++) {
var item = list[i];
if(item) {
this.addListItem(item);
}
}
}
/*
* Adds an item to the visual list of domains
*/
CsFire.XulWhitelist.addListItem = function(entry) {
var rules = document.getElementById('listcontents');
var item = document.createElement('treeitem');
var row = document.createElement('treerow');
// Add the domain
var c1 = document.createElement('treecell');
c1.setAttribute('label', entry.origin);
row.appendChild(c1);
// Add the domain
var c2 = document.createElement('treecell');
c2.setAttribute('label', entry.destination);
row.appendChild(c2);
// Add the enabled field
var c3 = document.createElement('treecell');
c3.setAttribute('value', entry.enabled);
row.appendChild(c3);
// Add entry to list
item.appendChild(row);
rules.appendChild(item);
}
/*
* Removes an item from the visual list of domains
*/
CsFire.XulWhitelist.removeListItem = function(node) {
var rules = document.getElementById('listcontents');
rules.removeChild(node);
}
/*
* Adds a URL to the whitelist (controller and view)
*/
CsFire.XulWhitelist.addEntry = function() {
var origin = document.getElementById('urlboxorigin');
var destination = document.getElementById('urlboxdestination');
var listItem = CsFire.Whitelist.addEntry(origin.value, destination.value);
if("error" in listItem) {
if("errororigin" in listItem) {
var style = origin.style;
style['color'] = "red";
}
if("errordestination" in listItem) {
var style = destination.style;
style['color'] = "red";
}
}
else {
this.addListItem(listItem);
origin.value="";
var style = origin.style;
style['color'] = null;
destination.value="";
var style = destination.style;
style['color'] = null;
}
this.updateAddButtonStatus();
}
/*
* Removes an entry from the whitelist (controller and view)
*/
CsFire.XulWhitelist.removeEntry = function() {
var toRemove = [];
var list = document.getElementById('whitelist');
var rules = document.getElementById('listcontents');
for (var i=rules.childNodes.length-1 ; i>=0 ; i--) {
if (list.view.selection.isSelected(i)) {
var node = rules.childNodes[i];
var origin = node.firstChild.childNodes[0].getAttribute('label');
var destination = node.firstChild.childNodes[1].getAttribute('label');
if(CsFire.Whitelist.removeEntry(origin, destination)) {
toRemove.push(node);
}
}
}
/*
* Delete all entries here (otherwise, you're modifying the list you're
* looping over
*/
for(var i = 0; i < toRemove.length; i++) {
this.removeListItem(toRemove[i]);
}
}